<?php

/**
 * This is the model class for table "unit_type".
 *
 * The followings are the available columns in table 'unit_type':
 * @property integer $id
 * @property string $name
 * @property string $resources
 * @property integer $food_count
 * @property integer $stat_atk
 * @property integer $stat_def
 * @property integer $stat_speed
 * @property integer $building_id
 * @property integer $building_lvl
 * @property integer $time_create
 */
class UnitType extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return UnitType the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'unit_type';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, resources, food_count, stat_atk, stat_def, stat_speed, building_id, building_lvl, time_create', 'required'),
			array('food_count, stat_atk, stat_def, stat_speed, building_id, building_lvl, time_create', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>15),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, resources, food_count, stat_atk, stat_def, stat_speed, building_id, building_lvl, time_create', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'resources' => 'Resources',
			'food_count' => 'Food Count',
			'stat_atk' => 'Stat Atk',
			'stat_def' => 'Stat Def',
			'stat_speed' => 'Stat Speed',
			'building_id' => 'Building',
			'building_lvl' => 'Building Lvl',
			'time_create' => 'Time Create',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('resources',$this->resources,true);
		$criteria->compare('food_count',$this->food_count);
		$criteria->compare('stat_atk',$this->stat_atk);
		$criteria->compare('stat_def',$this->stat_def);
		$criteria->compare('stat_speed',$this->stat_speed);
		$criteria->compare('building_id',$this->building_id);
		$criteria->compare('building_lvl',$this->building_lvl);
		$criteria->compare('time_create',$this->time_create);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}